<?php
namespace app\common\model;

class SendSms extends Base
{
    public static function check($mobile, $code)
    {
        $info = self::where('mobile', $mobile)->order('id DESC')->find();

        if(!$info) return '手机号不存在';
        if(time() - strtotime($info['create_time']) > $info['expiration_time']) return '验证码已过期';
        if($info['is_use'] == 1) return '验证码已使用';
        if($info['code'] != $code) return '验证码错误';

        self::edit(['id' => $info['id'], 'is_use' => 1]);

        return true;
    }
}